package logic

import (
	"context"
	"goods_srv/cache"

	"goods_srv/goods"
	"goods_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type TotalCartLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewTotalCartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TotalCartLogic {
	return &TotalCartLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *TotalCartLogic) TotalCart(in *goods.TotalCartRequest) (*goods.TotalCartResponse, error) {
	// todo: add your logic here and delete this line

	num, price := cache.TotalCart(int(in.UserId))

	return &goods.TotalCartResponse{
		Num:   int64(num),
		Price: float32(price),
	}, nil
}
